﻿#include "JsonParser.h"

#include <qfile.h>
#include <qjsondocument.h>
#include <qjsonobject.h>
#include <qjsonarray.h>
#include <qjsonvalue.h>
#include <qvector.h>
#include <qlist.h>
#include <qdebug.h>
#include <qdir.h>
#include <qsharedpointer.h>

#include "TextFileParser.h"

namespace
{
    bool JsonArrayToDouble(const QJsonArray& jsonArray, QVector<double>& result)
    {
        QVector<double> resultTmp;
        for (int i = 0; i < jsonArray.size(); ++i)
        {
            if (!jsonArray.at(i).isDouble())
            {
                return false;
            }
            resultTmp.append(jsonArray.at(i).toDouble());
        }
        result = std::move(resultTmp);
        return true;
    }

    bool JsonArrayToString(const QJsonArray& jsonArray, QVector<QString>& result)
    {
        QVector<QString> resultTmp;
        for (int i = 0; i < jsonArray.size(); ++i)
        {
            if (!jsonArray.at(i).isString())
            {
                return false;
            }
            resultTmp.append(jsonArray.at(i).toString());
        }
        result = std::move(resultTmp);
        return true;
    }

    pst::FileDataTypes GetFileDataTypes(int result_type)
    {
        pst::FileDataTypes fileDataTypes;
        switch (result_type)
        {
        case 0:
            fileDataTypes = pst::FileDataType::File2DCurve | pst::FileDataType::FileTwoDHeatMap | pst::FileDataType::FileThreeDCloudMap;
            break;
        case 1:
            fileDataTypes = pst::FileDataType::File2DCurve | pst::FileDataType::FileTwoDHeatMap;
            break;
        case 2:
            fileDataTypes = pst::FileDataType::File2DCurve;
            break;
        case 3:
            fileDataTypes = pst::FileDataType::FileSurfaceElectricFieldGraph;
            break;
        case 4:
            fileDataTypes = pst::FileDataType::FileSurfaceElectricFieldGraph;
            break;
        case 5:
            fileDataTypes = pst::FileDataType::FileSurfaceElectricFieldGraph;
            break;
        case 6:
            fileDataTypes = pst::FileDataType::FileSurfaceElectricFieldGraph;
            break;
        case 7:
            fileDataTypes = pst::FileDataType::File2DCurve | pst::FileDataType::FilePolar | pst::FileDataType::FileThreeDSurfacePlot;
            break;
        case 8:
            fileDataTypes = pst::FileDataType::File2DCurve;
            break;
        case 9:
            fileDataTypes = pst::FileDataType::File2DCurve;
            break;
        case 10:
            fileDataTypes = pst::FileDataType::File2DCurve;
            break;
        case 11:
            fileDataTypes = pst::FileDataType::File2DCurve;
            break;
        case 12:
            fileDataTypes = pst::FileDataType::None;
            break;
        case 13:
            fileDataTypes = pst::FileDataType::None;
            break;
        case 14:
            fileDataTypes = pst::FileDataType::FileSurfaceElectricFieldGraph;
            break;
        case 15:
            fileDataTypes = pst::FileDataType::File2DCurve | pst::FileDataType::FileTwoDHeatMap;
            break;
        default:
            fileDataTypes = pst::FileDataType::None;
            break;
        }
        return fileDataTypes;
    }

    QString GetResultDataType(int result_type)
    {
        QString resultDataType;
        switch (result_type)
        {
        case 0:
        case 1:
            resultDataType = QObject::tr("电场分布数据");
            break;
        case 2:
            resultDataType = QObject::tr("点电场数据");
            break;
        case 3:
            resultDataType = QObject::tr("表面场分布数据");
            break;
        case 4:
            resultDataType = QObject::tr("表面电流密度数据");
            break;
        case 5:
            resultDataType = QObject::tr("空间电势分布数据");
            break;
        case 6:
            resultDataType = QObject::tr("表面电势分布数据");
            break;
        case 7:
            resultDataType = QObject::tr("方向图数据");
            break;
        case 8:
            resultDataType = QObject::tr("S参数数据");
            break;
        case 9:
            resultDataType = QObject::tr("驻波比数据");
            break;
        case 10:
            resultDataType = QObject::tr("电压数据");
            break;
        case 11:
            resultDataType = QObject::tr("电流数据");
            break;
        case 12:
            resultDataType = QObject::tr("干扰关联矩阵数据");
            break;
        case 13:
            resultDataType = QObject::tr("SAR仿真数据");
            break;
        case 14:
            resultDataType = QObject::tr("附着点数据");
            break;
        case 15:
            resultDataType = QObject::tr("面电势分布数据");
            break;
        default:
            break;
        }
        return resultDataType;
    }
} // namespace

namespace pst
{
    QString GetSimulationScenario(int sim_scene)
    {
        QString simulationScenario;
        switch (sim_scene)
        {
        case 0:
            simulationScenario = QObject::tr("雷电仿真");
            break;
        case 1:
            simulationScenario = QObject::tr("HIRF");
            break;
        case 2:
            simulationScenario = QObject::tr("高功率微波");
            break;
        case 3:
            simulationScenario = QObject::tr("核电磁脉冲仿真");
            break;
        case 4:
            simulationScenario = QObject::tr("天线与多天线布局仿真");
            break;
        case 5:
            simulationScenario = QObject::tr("静电场仿真");
            break;
        default:
            break;
        }
        return simulationScenario;
    }

    JsonParser* JsonParser::GetInstance()
    {
        static JsonParser instance;
        return &instance;
    }

    JsonParser::JsonParser(QObject* parent)
    {
    }

    JsonParser::~JsonParser()
    {
    }

    void JsonParser::AddResultData(const ProjectDataPointer& projectDataPointer)
    {
        if (!projectDataPointer->projectFileData.isEmpty() || !projectDataPointer->projectResultData.isEmpty())
        {
            m_projectDataList.append(projectDataPointer);
        }
    }

    JsonParser::ResultInfo JsonParser::GetResultData(const QVector<QString>& filepathArray)
    {
        ResultInfo resultInfo;
        resultInfo.projectData = ProjectDataPointer::create();
        ProjectDataPointer& projectData = resultInfo.projectData;
        for (const QString& filePath : filepathArray)
        {
            ResultDataInfo* resultDataInfo = new ResultDataInfo();
            resultDataInfo->isDir = false;
            resultDataInfo->path = filePath;
            resultDataInfo->fileType = FileDataType::File2DCurve | FileDataType::FileTwoDHeatMap;
            if (QFile::exists(filePath))
            {
                projectData->projectResultData.append(ResultDataPointer(resultDataInfo));
            }
            else
            {
                qDebug() << filePath << " 文件不存在！！！";
                resultInfo.errorMessageList.append(filePath);
                delete resultDataInfo;
            }
        }
        if (!projectData->projectFileData.isEmpty() || !projectData->projectResultData.isEmpty())
        {
            m_projectDataList.append(projectData);
        }
        return resultInfo;
    }

    static void SetInputJsonData(HearderFileInfo& hearderFileInfo, const QString& filePath)
    {
        if (hearderFileInfo.sim_project_info.sim_scene != 4)
        {
            return;
        }
        QFile file("./input.json");
        if (!file.open(QIODevice::ReadOnly))
        {
            return;
        }
        QByteArray jsonText = file.readAll();
        file.close();
        QString modelPath;
        QVector<ResultFileInfo::ModelPosition> positions;
        QJsonParseError jsonError;
        QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonText, &jsonError);
        if (!jsonDocument.isNull() && (jsonError.error == QJsonParseError::NoError))
        {
            if (jsonDocument.isObject())
            {
                QJsonObject jsonObject = jsonDocument.object();
                modelPath = jsonObject.value("cadModel").toString();
                QJsonArray lines = jsonObject.value("lines").toArray();
                for (int i = 0; i < lines.size(); ++i)
                {
                    QJsonObject object = lines.at(i).toObject();
                    ResultFileInfo::ModelPosition pos{};
                    pos.position_X = object.value("x").toDouble() * 1000.0;
                    pos.position_Y = object.value("y").toDouble() * 1000.0;
                    pos.position_Z = object.value("z").toDouble() * 1000.0;
                    pos.rotate_Theta = object.value("theta").toDouble();
                    pos.rotate_Phi = object.value("phi").toDouble();
                    positions.append(pos);
                }
            }
        }
        auto currentDir = QDir::current();
        auto fileInfoList = currentDir.entryInfoList(QStringList("*.json"), QDir::Files);
        int index = -1;
        for (const auto& fileInfo : fileInfoList)
        {
            if (!fileInfo.completeBaseName().contains("result", Qt::CaseInsensitive))
            {
                continue;
            }
            ++index;
            if (fileInfo.absoluteFilePath() == filePath)
            {
                break;
            }
        }
        for (auto& result_info : hearderFileInfo.result_info)
        {
            if (result_info->result_type != 7)
            {
                continue;
            }
            hearderFileInfo.sim_project_info.geometry_file_name = {modelPath};
            if (index >= 0 && index < positions.size())
            {
                result_info->Antenna_position = positions.at(index);
            }
        }
    }

    JsonParser::ResultInfo JsonParser::GetProjectInfo(const QString& filePath)
    {
        ResultInfo resultInfo;
        resultInfo.projectData = ProjectDataPointer::create();
        QFile file(filePath);
        if (!file.open(QIODevice::ReadOnly))
        {
            qDebug() << filePath << " open error!!!";
            resultInfo.errorMessageList.append(filePath + " open error!!!");
            return resultInfo;
        }
        QByteArray jsonText = file.readAll();
        file.close();
        QJsonParseError jsonError;
        QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonText, &jsonError);
        // if (!jsonDocument.isNull() && (jsonError.error == QJsonParseError::NoError)) {
        //     if (jsonDocument.isArray()) {
        //         QJsonArray jsonArray = jsonDocument.array();
        //         for (int i = 0; i < jsonArray.size(); ++i) {
        //             QJsonObject jsonObject = jsonArray.at(i).toObject();
        //             HearderFileInfo heardFileInfo;
        //             heardFileInfo.result_type = jsonObject.value("result_type").toString();
        //             heardFileInfo.headfile_name = jsonObject.value("headfile_name").toString();
        //             heardFileInfo.headfile_path = jsonObject.value("headfile_path").toString();
        //             GetHeardData(resultInfo, heardFileInfo);
        //         }
        //     }
        // }
        if (!jsonDocument.isNull() && (jsonError.error == QJsonParseError::NoError))
        {
            if (jsonDocument.isObject())
            {
                HearderFileInfo hearderFileInfo;
                QJsonObject jsonObject = jsonDocument.object();
                // 获取sim_project_info
                if (!jsonObject.contains("sim_project_info"))
                {
                    resultInfo.errorMessageList.append("'sim_project_info'字段不存在");
                }
                else
                {
                    if (!jsonObject.value("sim_project_info").isObject())
                    {
                        resultInfo.errorMessageList.append("'sim_project_info'字段数据类型错误");
                    }
                    else
                    {
                        QJsonObject sim_project_info = jsonObject.value("sim_project_info").toObject();
                        // 获取pre_design_name
                        if (!sim_project_info.contains("pre_design_name"))
                        {
                            resultInfo.errorMessageList.append("'pre_design_name'字段不存在");
                        }
                        else
                        {
                            if (!sim_project_info.value("pre_design_name").isString())
                            {
                                resultInfo.errorMessageList.append("'pre_design_name'字段数据类型错误");
                            }
                            else
                            {
                                hearderFileInfo.sim_project_info.pre_design_name = sim_project_info.value("pre_design_name").toString();
                            }
                        }
                        // 获取sim_scene
                        if (!sim_project_info.contains("sim_scene"))
                        {
                            resultInfo.errorMessageList.append("'sim_scene'字段不存在");
                        }
                        else
                        {
                            if (!sim_project_info.value("sim_scene").isDouble())
                            {
                                resultInfo.errorMessageList.append("'sim_scene'字段数据类型错误");
                            }
                            else
                            {
                                hearderFileInfo.sim_project_info.sim_scene = sim_project_info.value("sim_scene").toInt();
                            }
                        }
                        // 获取name
                        if (!sim_project_info.contains("name"))
                        {
                            resultInfo.errorMessageList.append("'name'字段不存在");
                        }
                        else
                        {
                            if (!sim_project_info.value("name").isString())
                            {
                                resultInfo.errorMessageList.append("'name'字段数据类型错误");
                            }
                            else
                            {
                                hearderFileInfo.sim_project_info.name = sim_project_info.value("name").toString();
                            }
                        }
                        // 获取geometry_file_name
                        // if (!sim_project_info.contains("geometry_file_name"))
                        //{
                        //    resultInfo.errorMessageList.append("'geometry_file_name'字段不存在");
                        //}
                        // else
                        //{
                        //    if (!sim_project_info.value("geometry_file_name").isArray())
                        //    {
                        //        resultInfo.errorMessageList.append("'geometry_file_name'字段数据类型错误");
                        //    }
                        // else if (!JsonArrayToString(sim_project_info.value("geometry_file_name").toArray(), hearderFileInfo.sim_project_info.geometry_file_name))
                        JsonArrayToString(sim_project_info.value("geometry_file_name").toArray(), hearderFileInfo.sim_project_info.geometry_file_name);
                        //{
                        //    resultInfo.errorMessageList.append("'geometry_file_name'字段内部数据类型错误");
                        //}
                        //}
                    }
                }
                // 获取result_info
                if (!jsonObject.contains("result_info"))
                {
                    resultInfo.errorMessageList.append("'result_info'字段不存在");
                }
                else
                {
                    if (!jsonObject.value("result_info").isArray())
                    {
                        resultInfo.errorMessageList.append("'result_info'字段数据类型错误");
                    }
                    else
                    {
                        QJsonArray result_info = jsonObject.value("result_info").toArray();
                        for (int i = 0; i < result_info.size(); ++i)
                        {
                            ResultFilePointer resultFileInfo = ResultFilePointer::create();
                            QJsonObject object = result_info.at(i).toObject();
                            // 获取result_type
                            if (!object.contains("result_type"))
                            {
                                resultInfo.errorMessageList.append("'result_type'字段不存在");
                            }
                            else
                            {
                                if (!object.value("result_type").isDouble())
                                {
                                    resultInfo.errorMessageList.append("'result_type'字段数据类型错误");
                                }
                                else
                                {
                                    resultFileInfo->result_type = object.value("result_type").toInt();
                                }
                            }
                            // 获取result_folder_path
                            if (!object.contains("result_folder_path"))
                            {
                                resultInfo.errorMessageList.append("'result_folder_path'字段不存在");
                            }
                            else
                            {
                                if (!object.value("result_folder_path").isString())
                                {
                                    resultInfo.errorMessageList.append("'result_folder_path'字段数据类型错误");
                                }
                                else
                                {
                                    resultFileInfo->result_folder_path = object.value("result_folder_path").toString();
                                }
                            }
                            // 获取result_data_type
                            if (!object.contains("result_data_type"))
                            {
                                resultInfo.errorMessageList.append("'result_data_type'字段不存在");
                            }
                            else
                            {
                                if (!object.value("result_data_type").isDouble())
                                {
                                    resultInfo.errorMessageList.append("'result_data_type'字段数据类型错误");
                                }
                                else
                                {
                                    resultFileInfo->result_data_type = object.value("result_data_type").toInt();
                                }
                            }
                            // 获取result_data_name_td
                            if (!object.contains("result_data_name_td"))
                            {
                                resultInfo.errorMessageList.append("'result_data_name_td'字段不存在");
                            }
                            else
                            {
                                if (!object.value("result_data_name_td").isString())
                                {
                                    resultInfo.errorMessageList.append("'result_data_name_td'字段数据类型错误");
                                }
                                else
                                {
                                    resultFileInfo->result_data_name_td = object.value("result_data_name_td").toString();
                                }
                            }
                            // 获取result_data_name_fd
                            if (!object.contains("result_data_name_fd"))
                            {
                                resultInfo.errorMessageList.append("'result_data_name_fd'字段不存在");
                            }
                            else
                            {
                                if (!object.value("result_data_name_fd").isString())
                                {
                                    resultInfo.errorMessageList.append("'result_data_name_fd'字段数据类型错误");
                                }
                                else
                                {
                                    resultFileInfo->result_data_name_fd = object.value("result_data_name_fd").toString();
                                }
                            }
                            // 获取result_data_folder_name_td
                            if (!object.contains("result_data_folder_name_td"))
                            {
                                resultInfo.errorMessageList.append("'result_data_folder_name_td'字段不存在");
                            }
                            else
                            {
                                if (!object.value("result_data_folder_name_td").isString())
                                {
                                    resultInfo.errorMessageList.append("'result_data_folder_name_td'字段数据类型错误");
                                }
                                else
                                {
                                    resultFileInfo->result_data_folder_name_td = object.value("result_data_folder_name_td").toString();
                                }
                            }
                            // 获取result_data_folder_name_fd
                            if (!object.contains("result_data_folder_name_fd"))
                            {
                                resultInfo.errorMessageList.append("'result_data_folder_name_fd'字段不存在");
                            }
                            else
                            {
                                if (!object.value("result_data_folder_name_fd").isString())
                                {
                                    resultInfo.errorMessageList.append("'result_data_folder_name_fd'字段数据类型错误");
                                }
                                else
                                {
                                    resultFileInfo->result_data_folder_name_fd = object.value("result_data_folder_name_fd").toString();
                                }
                            }
                            // 获取time_unit
                            if (!object.contains("time_unit"))
                            {
                                resultInfo.errorMessageList.append("'time_unit'字段不存在");
                            }
                            else
                            {
                                if (!object.value("time_unit").isString())
                                {
                                    resultInfo.errorMessageList.append("'time_unit'字段数据类型错误");
                                }
                                else
                                {
                                    resultFileInfo->time_unit = object.value("time_unit").toString();
                                }
                            }
                            // 获取time_data
                            if (!object.contains("time_data"))
                            {
                                resultInfo.errorMessageList.append("'time_data'字段不存在");
                            }
                            else
                            {
                                if (!object.value("time_data").isArray())
                                {
                                    resultInfo.errorMessageList.append("'time_data'字段数据类型错误");
                                }
                                else if (!JsonArrayToDouble(object.value("time_data").toArray(), resultFileInfo->time_data))
                                {
                                    resultInfo.errorMessageList.append("'time_data'字段内部数据类型错误");
                                }
                            }
                            // 获取frequency_unit
                            if (!object.contains("frequency_unit"))
                            {
                                resultInfo.errorMessageList.append("'frequency_unit'字段不存在");
                            }
                            else
                            {
                                if (!object.value("frequency_unit").isString())
                                {
                                    resultInfo.errorMessageList.append("'frequency_unit'字段数据类型错误");
                                }
                                else
                                {
                                    resultFileInfo->frequency_unit = object.value("frequency_unit").toString();
                                }
                            }
                            // 获取frequency_data
                            if (!object.contains("frequency_data"))
                            {
                                resultInfo.errorMessageList.append("'frequency_data'字段不存在");
                            }
                            else
                            {
                                if (!object.value("frequency_data").isArray())
                                {
                                    resultInfo.errorMessageList.append("'frequency_data'字段数据类型错误");
                                }
                                else if (!JsonArrayToDouble(object.value("frequency_data").toArray(), resultFileInfo->frequency_data))
                                {
                                    resultInfo.errorMessageList.append("'frequency_data'字段内部数据类型错误");
                                }
                            }
                            // 获取field_monitor_type
                            // if (!object.contains("field_monitor_type"))
                            //{
                            //    resultInfo.errorMessageList.append("'field_monitor_type'字段不存在");
                            //}
                            // else
                            //{
                            //    if (!object.value("field_monitor_type").isDouble())
                            //    {
                            //        resultInfo.errorMessageList.append("'field_monitor_type'字段数据类型错误");
                            //    }
                            //    else
                            //    {
                            resultFileInfo->field_monitor_type = object.value("field_monitor_type").toInt();
                            //    }
                            //}
                            // 获取field_monitor_unit
                            if (!object.contains("field_monitor_unit"))
                            {
                                resultInfo.errorMessageList.append("'field_monitor_unit'字段不存在");
                            }
                            else
                            {
                                if (!object.value("field_monitor_unit").isString())
                                {
                                    resultInfo.errorMessageList.append("'field_monitor_unit'字段数据类型错误");
                                }
                                else
                                {
                                    resultFileInfo->field_monitor_unit = object.value("field_monitor_unit").toString();
                                }
                            }
                            // 获取field_monitor_sample_info
                            if (!object.contains("field_monitor_sample_info"))
                            {
                                resultInfo.errorMessageList.append("'field_monitor_sample_info'字段不存在");
                            }
                            else
                            {
                                if (!object.value("field_monitor_sample_info").isObject())
                                {
                                    resultInfo.errorMessageList.append("'field_monitor_sample_info'字段数据类型错误");
                                }
                                else
                                {
                                    QJsonObject field_monitor_sample_info = object.value("field_monitor_sample_info").toObject();
                                    // 获取sta_x
                                    if (!field_monitor_sample_info.contains("sta_x"))
                                    {
                                        resultFileInfo->field_monitor_sample_info.sta_x = std::numeric_limits<double>::quiet_NaN();
                                    }
                                    else
                                    {
                                        if (!field_monitor_sample_info.value("sta_x").isDouble() &&
                                            (field_monitor_sample_info.value("sta_x").isString() && !field_monitor_sample_info.value("sta_x").toString().isEmpty()))
                                        {
                                            resultInfo.errorMessageList.append("'sta_x'字段数据类型错误");
                                        }
                                        else
                                        {
                                            resultFileInfo->field_monitor_sample_info.sta_x = field_monitor_sample_info.value("sta_x").toDouble();
                                        }
                                    }
                                    // 获取end_x
                                    if (!field_monitor_sample_info.contains("end_x"))
                                    {
                                        resultFileInfo->field_monitor_sample_info.end_x = std::numeric_limits<double>::quiet_NaN();
                                    }
                                    else
                                    {
                                        if (!field_monitor_sample_info.value("end_x").isDouble() &&
                                            (field_monitor_sample_info.value("end_x").isString() && !field_monitor_sample_info.value("end_x").toString().isEmpty()))
                                        {
                                            resultInfo.errorMessageList.append("'end_x'字段数据类型错误");
                                        }
                                        else
                                        {
                                            resultFileInfo->field_monitor_sample_info.end_x = field_monitor_sample_info.value("end_x").toDouble();
                                        }
                                    }
                                    // 获取num_x
                                    if (!field_monitor_sample_info.contains("num_x"))
                                    {
                                        resultFileInfo->field_monitor_sample_info.num_x = std::numeric_limits<double>::quiet_NaN();
                                    }
                                    else
                                    {
                                        if (!field_monitor_sample_info.value("num_x").isDouble() &&
                                            (field_monitor_sample_info.value("num_x").isString() && !field_monitor_sample_info.value("num_x").toString().isEmpty()))
                                        {
                                            resultInfo.errorMessageList.append("'num_x'字段数据类型错误");
                                        }
                                        else
                                        {
                                            resultFileInfo->field_monitor_sample_info.num_x = field_monitor_sample_info.value("num_x").toInt();
                                        }
                                    }
                                    // 获取sta_y
                                    if (!field_monitor_sample_info.contains("sta_y"))
                                    {
                                        resultFileInfo->field_monitor_sample_info.sta_y = std::numeric_limits<double>::quiet_NaN();
                                    }
                                    else
                                    {
                                        if (!field_monitor_sample_info.value("sta_y").isDouble() &&
                                            (field_monitor_sample_info.value("sta_y").isString() && !field_monitor_sample_info.value("sta_y").toString().isEmpty()))
                                        {
                                            resultInfo.errorMessageList.append("'sta_y'字段数据类型错误");
                                        }
                                        else
                                        {
                                            resultFileInfo->field_monitor_sample_info.sta_y = field_monitor_sample_info.value("sta_y").toDouble();
                                        }
                                    }
                                    // 获取end_y
                                    if (!field_monitor_sample_info.contains("end_y"))
                                    {
                                        resultFileInfo->field_monitor_sample_info.end_y = std::numeric_limits<double>::quiet_NaN();
                                    }
                                    else
                                    {
                                        if (!field_monitor_sample_info.value("end_y").isDouble() &&
                                            (field_monitor_sample_info.value("end_y").isString() && !field_monitor_sample_info.value("end_y").toString().isEmpty()))
                                        {
                                            resultInfo.errorMessageList.append("'end_y'字段数据类型错误");
                                        }
                                        else
                                        {
                                            resultFileInfo->field_monitor_sample_info.end_y = field_monitor_sample_info.value("end_y").toDouble();
                                        }
                                    }
                                    // 获取num_y
                                    if (!field_monitor_sample_info.contains("num_y"))
                                    {
                                        resultFileInfo->field_monitor_sample_info.num_y = std::numeric_limits<double>::quiet_NaN();
                                    }
                                    else
                                    {
                                        if (!field_monitor_sample_info.value("num_y").isDouble() &&
                                            (field_monitor_sample_info.value("num_y").isString() && !field_monitor_sample_info.value("num_y").toString().isEmpty()))
                                        {
                                            resultInfo.errorMessageList.append("'num_y'字段数据类型错误");
                                        }
                                        else
                                        {
                                            resultFileInfo->field_monitor_sample_info.num_y = field_monitor_sample_info.value("num_y").toInt();
                                        }
                                    }
                                    // 获取sta_z
                                    if (!field_monitor_sample_info.contains("sta_z"))
                                    {
                                        resultFileInfo->field_monitor_sample_info.sta_z = std::numeric_limits<double>::quiet_NaN();
                                    }
                                    else
                                    {
                                        if (!field_monitor_sample_info.value("sta_z").isDouble() &&
                                            (field_monitor_sample_info.value("sta_z").isString() && !field_monitor_sample_info.value("sta_z").toString().isEmpty()))
                                        {
                                            resultInfo.errorMessageList.append("'sta_z'字段数据类型错误");
                                        }
                                        else
                                        {
                                            resultFileInfo->field_monitor_sample_info.sta_z = field_monitor_sample_info.value("sta_z").toDouble();
                                        }
                                    }
                                    // 获取end_z
                                    if (!field_monitor_sample_info.contains("end_z"))
                                    {
                                        resultFileInfo->field_monitor_sample_info.end_z = std::numeric_limits<double>::quiet_NaN();
                                    }
                                    else
                                    {
                                        if (!field_monitor_sample_info.value("end_z").isDouble() &&
                                            (field_monitor_sample_info.value("end_z").isString() && !field_monitor_sample_info.value("end_z").toString().isEmpty()))
                                        {
                                            resultInfo.errorMessageList.append("'end_z'字段数据类型错误");
                                        }
                                        else
                                        {
                                            resultFileInfo->field_monitor_sample_info.end_z = field_monitor_sample_info.value("end_z").toDouble();
                                        }
                                    }
                                    // 获取num_z
                                    if (!field_monitor_sample_info.contains("num_z"))
                                    {
                                        resultFileInfo->field_monitor_sample_info.num_z = std::numeric_limits<double>::quiet_NaN();
                                    }
                                    else
                                    {
                                        if (!field_monitor_sample_info.value("num_z").isDouble() &&
                                            (field_monitor_sample_info.value("num_z").isString() && !field_monitor_sample_info.value("num_z").toString().isEmpty()))
                                        {
                                            resultInfo.errorMessageList.append("'num_z'字段数据类型错误");
                                        }
                                        else
                                        {
                                            resultFileInfo->field_monitor_sample_info.num_z = field_monitor_sample_info.value("num_z").toInt();
                                        }
                                    }
                                    // 获取sta_theta
                                    if (!field_monitor_sample_info.contains("sta_theta"))
                                    {
                                        resultFileInfo->field_monitor_sample_info.sta_theta = std::numeric_limits<double>::quiet_NaN();
                                    }
                                    else
                                    {
                                        if (!field_monitor_sample_info.value("sta_theta").isDouble() &&
                                            (field_monitor_sample_info.value("sta_theta").isString() && !field_monitor_sample_info.value("sta_theta").toString().isEmpty()))
                                        {
                                            resultInfo.errorMessageList.append("'sta_theta'字段数据类型错误");
                                        }
                                        else
                                        {
                                            resultFileInfo->field_monitor_sample_info.sta_theta = field_monitor_sample_info.value("sta_theta").toDouble();
                                        }
                                    }
                                    // 获取end_theta
                                    if (!field_monitor_sample_info.contains("end_theta"))
                                    {
                                        resultFileInfo->field_monitor_sample_info.end_theta = std::numeric_limits<double>::quiet_NaN();
                                    }
                                    else
                                    {
                                        if (!field_monitor_sample_info.value("end_theta").isDouble() &&
                                            (field_monitor_sample_info.value("end_theta").isString() && !field_monitor_sample_info.value("end_theta").toString().isEmpty()))
                                        {
                                            resultInfo.errorMessageList.append("'end_theta'字段数据类型错误");
                                        }
                                        else
                                        {
                                            resultFileInfo->field_monitor_sample_info.end_theta = field_monitor_sample_info.value("end_theta").toDouble();
                                        }
                                    }
                                    // 获取num_theta
                                    if (!field_monitor_sample_info.contains("num_theta"))
                                    {
                                        resultFileInfo->field_monitor_sample_info.num_theta = std::numeric_limits<double>::quiet_NaN();
                                    }
                                    else
                                    {
                                        if (!field_monitor_sample_info.value("num_theta").isDouble() &&
                                            (field_monitor_sample_info.value("num_theta").isString() && !field_monitor_sample_info.value("num_theta").toString().isEmpty()))
                                        {
                                            resultInfo.errorMessageList.append("'num_theta'字段数据类型错误");
                                        }
                                        else
                                        {
                                            resultFileInfo->field_monitor_sample_info.num_theta = field_monitor_sample_info.value("num_theta").toInt();
                                        }
                                    }
                                    // 获取sta_phi
                                    if (!field_monitor_sample_info.contains("sta_phi"))
                                    {
                                        resultFileInfo->field_monitor_sample_info.sta_phi = std::numeric_limits<double>::quiet_NaN();
                                    }
                                    else
                                    {
                                        if (!field_monitor_sample_info.value("sta_phi").isDouble() &&
                                            (field_monitor_sample_info.value("sta_phi").isString() && !field_monitor_sample_info.value("sta_phi").toString().isEmpty()))
                                        {
                                            resultInfo.errorMessageList.append("'sta_phi'字段数据类型错误");
                                        }
                                        else
                                        {
                                            resultFileInfo->field_monitor_sample_info.sta_phi = field_monitor_sample_info.value("sta_phi").toDouble();
                                        }
                                    }
                                    // 获取end_phi
                                    if (!field_monitor_sample_info.contains("end_phi"))
                                    {
                                        resultFileInfo->field_monitor_sample_info.end_phi = std::numeric_limits<double>::quiet_NaN();
                                    }
                                    else
                                    {
                                        if (!field_monitor_sample_info.value("end_phi").isDouble() &&
                                            (field_monitor_sample_info.value("end_phi").isString() && !field_monitor_sample_info.value("end_phi").toString().isEmpty()))
                                        {
                                            resultInfo.errorMessageList.append("'end_phi'字段数据类型错误");
                                        }
                                        else
                                        {
                                            resultFileInfo->field_monitor_sample_info.end_phi = field_monitor_sample_info.value("end_phi").toDouble();
                                        }
                                    }
                                    // 获取num_phi
                                    if (!field_monitor_sample_info.contains("num_phi"))
                                    {
                                        resultFileInfo->field_monitor_sample_info.num_phi = std::numeric_limits<double>::quiet_NaN();
                                    }
                                    else
                                    {
                                        if (!field_monitor_sample_info.value("num_phi").isDouble() &&
                                            (field_monitor_sample_info.value("num_phi").isString() && !field_monitor_sample_info.value("num_phi").toString().isEmpty()))
                                        {
                                            resultInfo.errorMessageList.append("'num_phi'字段数据类型错误");
                                        }
                                        else
                                        {
                                            resultFileInfo->field_monitor_sample_info.num_phi = field_monitor_sample_info.value("num_phi").toInt();
                                        }
                                    }
                                }
                            }
                            // 获取Antenna_position
                            if (!object.contains("Antenna_position"))
                            {
                                // resultInfo.errorMessageList.append("'Antenna_position'字段不存在");
                            }
                            else
                            {
                                if (!object.value("Antenna_position").isObject())
                                {
                                    // resultInfo.errorMessageList.append("'Antenna_position'字段数据类型错误");
                                }
                                else
                                {
                                    QJsonObject Antenna_position = object.value("Antenna_position").toObject();
                                    // 获取position_X
                                    // if (!Antenna_position.contains("position_X"))
                                    //{
                                    //    resultFileInfo->Antenna_position.position_X = std::numeric_limits<double>::quiet_NaN();
                                    //}
                                    // else
                                    //{
                                    //    if (!Antenna_position.value("position_X").isDouble() &&
                                    //        (Antenna_position.value("position_X").isString() && !Antenna_position.value("position_X").toString().isEmpty()))
                                    //    {
                                    //        resultInfo.errorMessageList.append("'position_X'字段数据类型错误");
                                    //    }
                                    //    else
                                    //    {
                                    resultFileInfo->Antenna_position.position_X = Antenna_position.value("position_X").toDouble();
                                    //    }
                                    //}
                                    // 获取position_Y
                                    // if (!Antenna_position.contains("position_Y"))
                                    //{
                                    //    resultFileInfo->Antenna_position.position_Y = std::numeric_limits<double>::quiet_NaN();
                                    //}
                                    // else
                                    //{
                                    //    if (!Antenna_position.value("position_Y").isDouble() &&
                                    //        (Antenna_position.value("position_Y").isString() && !Antenna_position.value("position_Y").toString().isEmpty()))
                                    //    {
                                    //        resultInfo.errorMessageList.append("'position_Y'字段数据类型错误");
                                    //    }
                                    //    else
                                    //    {
                                    resultFileInfo->Antenna_position.position_Y = Antenna_position.value("position_Y").toDouble();
                                    //    }
                                    //}
                                    // 获取position_Z
                                    // if (!Antenna_position.contains("position_Z"))
                                    //{
                                    //    resultFileInfo->Antenna_position.position_Z = std::numeric_limits<double>::quiet_NaN();
                                    //}
                                    // else
                                    //{
                                    //    if (!Antenna_position.value("position_Z").isDouble() &&
                                    //        (Antenna_position.value("position_Z").isString() && !Antenna_position.value("position_Z").toString().isEmpty()))
                                    //    {
                                    //        resultInfo.errorMessageList.append("'position_Z'字段数据类型错误");
                                    //    }
                                    //    else
                                    //    {
                                    resultFileInfo->Antenna_position.position_Z = Antenna_position.value("position_Z").toDouble();
                                    //    }
                                    //}
                                    // 获取rotate_Theta
                                    // if (!Antenna_position.contains("rotate_Theta"))
                                    //{
                                    //    resultFileInfo->Antenna_position.rotate_Theta = std::numeric_limits<double>::quiet_NaN();
                                    //}
                                    // else
                                    //{
                                    //    if (!Antenna_position.value("rotate_Theta").isDouble() &&
                                    //        (Antenna_position.value("rotate_Theta").isString() && !Antenna_position.value("rotate_Theta").toString().isEmpty()))
                                    //    {
                                    //        resultInfo.errorMessageList.append("'rotate_Theta'字段数据类型错误");
                                    //    }
                                    //    else
                                    //    {
                                    resultFileInfo->Antenna_position.rotate_Theta = Antenna_position.value("rotate_Theta").toDouble();
                                    //    }
                                    //}
                                    // 获取rotate_Phi
                                    // if (!Antenna_position.contains("rotate_Phi"))
                                    //{
                                    //    resultFileInfo->Antenna_position.rotate_Phi = std::numeric_limits<double>::quiet_NaN();
                                    //}
                                    // else
                                    //{
                                    //    if (!Antenna_position.value("rotate_Phi").isDouble() &&
                                    //        (Antenna_position.value("rotate_Phi").isString() && !Antenna_position.value("rotate_Phi").toString().isEmpty()))
                                    //    {
                                    //        resultInfo.errorMessageList.append("'rotate_Phi'字段数据类型错误");
                                    //    }
                                    //    else
                                    //    {
                                    resultFileInfo->Antenna_position.rotate_Phi = Antenna_position.value("rotate_Phi").toDouble();
                                    //    }
                                    //}
                                }
                            }
                            GetResultData(resultInfo, resultFileInfo);
                            if (!resultFileInfo->result_data.isEmpty())
                            {
                                hearderFileInfo.result_info.append(std::move(resultFileInfo));
                            }
                        }
                        SetInputJsonData(hearderFileInfo, filePath);
                    }
                }
                if (!hearderFileInfo.result_info.isEmpty())
                {
                    resultInfo.projectData->projectFileData.append(std::move(hearderFileInfo));
                }
            }
            else
            {
                resultInfo.errorMessageList.append("json文件内容格式错误");
            }
        }
        else
        {
            resultInfo.errorMessageList.append(jsonError.errorString());
        }
        ProjectDataPointer& projectData = resultInfo.projectData;
        if (!projectData->projectFileData.isEmpty() || !projectData->projectResultData.isEmpty())
        {
            m_projectDataList.append(projectData);
        }
        return resultInfo;
    }

    void JsonParser::GetResultData(ResultInfo& resultInfo, ResultFilePointer& resultFileInfo)
    {
        QString folder_path = resultFileInfo->result_folder_path;
        // 获取result_data_name_td
        if (!resultFileInfo->result_data_name_td.isEmpty())
        {
            QString filePath;
            QDir dir(folder_path);
            const auto& fileInfoList = dir.entryInfoList(QDir::Files);
            for (const auto& fileInfo : fileInfoList)
            {
                if (fileInfo.fileName() == resultFileInfo->result_data_name_td)
                {
                    filePath = fileInfo.absoluteFilePath();
                    break;
                }
            }
            if (!filePath.isEmpty())
            {
                auto resultDataPointer = ResultDataPointer::create();
                resultDataPointer->isDir = false;
                resultDataPointer->path = filePath;
                resultDataPointer->resultDataType = GetResultDataType(resultFileInfo->result_type) + "_时域";
                resultDataPointer->fileType = GetFileDataTypes(resultFileInfo->result_type);
                resultDataPointer->resultFileInfo = resultFileInfo.toWeakRef();
                resultInfo.projectData->projectResultData.append(resultDataPointer);
                resultFileInfo->result_data.append(std::move(resultDataPointer));
            }
            else
            {
                QString resultDataPath = dir.absolutePath() + '/' + resultFileInfo->result_data_name_td;
                qDebug() << resultDataPath << " 文件不存在！！！";
                resultInfo.waringMessgaeList.append(resultDataPath + " 文件不存在！！！");
            }
        }
        // 获取result_data_name_fd
        if (!resultFileInfo->result_data_name_fd.isEmpty())
        {
            QString filePath;
            QDir dir(folder_path);
            const auto& fileInfoList = dir.entryInfoList(QDir::Files);
            for (const auto& fileInfo : fileInfoList)
            {
                if (fileInfo.fileName() == resultFileInfo->result_data_name_fd)
                {
                    filePath = fileInfo.absoluteFilePath();
                    break;
                }
            }
            if (!filePath.isEmpty())
            {
                auto resultDataPointer = ResultDataPointer::create();
                resultDataPointer->isDir = false;
                resultDataPointer->path = filePath;
                resultDataPointer->resultDataType = GetResultDataType(resultFileInfo->result_type) + "_频域";
                resultDataPointer->fileType = GetFileDataTypes(resultFileInfo->result_type);
                resultDataPointer->resultFileInfo = resultFileInfo.toWeakRef();
                resultInfo.projectData->projectResultData.append(resultDataPointer);
                resultFileInfo->result_data.append(std::move(resultDataPointer));
            }
            else
            {
                QString resultDataPath = dir.absolutePath() + '/' + resultFileInfo->result_data_name_fd;
                qDebug() << resultDataPath << " 文件不存在！！！";
                resultInfo.waringMessgaeList.append(resultDataPath + " 文件不存在！！！");
            }
        }
        // 获取result_data_folder_name_td
        if (!resultFileInfo->result_data_folder_name_td.isEmpty())
        {
            QDir dir(folder_path);
            if (dir.cd(resultFileInfo->result_data_folder_name_td))
            {
                auto resultDataPointer = ResultDataPointer::create();
                resultDataPointer->isDir = true;
                resultDataPointer->path = dir.absolutePath();
                resultDataPointer->resultDataType = GetResultDataType(resultFileInfo->result_type) + "_时域";
                resultDataPointer->fileType = GetFileDataTypes(resultFileInfo->result_type);
                resultDataPointer->resultFileInfo = resultFileInfo.toWeakRef();
                QVector<double> data;
                data = resultFileInfo->time_data;
                resultDataPointer->mulitFileInfo.first = qMakePair(1, resultFileInfo->time_unit);
                const auto& fileInfoList = dir.entryInfoList(QDir::Files).toVector();
                int minLength = std::min(data.size(), fileInfoList.size());
                for (int i = 0; i < minLength; ++i)
                {
                    resultDataPointer->mulitFileInfo.second.append(qMakePair(data.at(i), fileInfoList.at(i).absoluteFilePath()));
                }
                resultInfo.projectData->projectResultData.append(resultDataPointer);
                resultFileInfo->result_data.append(std::move(resultDataPointer));
            }
            else
            {
                const auto& path = dir.absolutePath() + '/' + resultFileInfo->result_data_folder_name_td;
                qDebug() << path << " 文件夹不存在！！！";
                resultInfo.waringMessgaeList.append(path + " 文件夹不存在！！！");
            }
        }
        // 获取result_data_folder_name_fd
        if (!resultFileInfo->result_data_folder_name_fd.isEmpty())
        {
            QDir dir(folder_path);
            if (dir.cd(resultFileInfo->result_data_folder_name_fd))
            {
                auto resultDataPointer = ResultDataPointer::create();
                resultDataPointer->isDir = true;
                resultDataPointer->path = dir.absolutePath();
                resultDataPointer->resultDataType = GetResultDataType(resultFileInfo->result_type) + "_频域";
                resultDataPointer->fileType = GetFileDataTypes(resultFileInfo->result_type);
                resultDataPointer->resultFileInfo = resultFileInfo.toWeakRef();
                QVector<double> data;
                data = resultFileInfo->frequency_data;
                resultDataPointer->mulitFileInfo.first = qMakePair(2, resultFileInfo->frequency_unit);
                const auto& fileInfoList = dir.entryInfoList(QDir::Files).toVector();
                int minLength = std::min(data.size(), fileInfoList.size());
                for (int i = 0; i < minLength; ++i)
                {
                    resultDataPointer->mulitFileInfo.second.append(qMakePair(data.at(i), fileInfoList.at(i).absoluteFilePath()));
                }
                resultInfo.projectData->projectResultData.append(resultDataPointer);
                resultFileInfo->result_data.append(std::move(resultDataPointer));
            }
            else
            {
                const auto& path = dir.absolutePath() + '/' + resultFileInfo->result_data_folder_name_fd;
                qDebug() << path << " 文件夹不存在！！！";
                resultInfo.waringMessgaeList.append(path + " 文件夹不存在！！！");
            }
        }
    }
} // namespace pst
